package com.xb.sourest.base;


import android.os.Bundle;

import com.gyf.immersionbar.ImmersionBar;
import com.xb.sourest.R;
import com.xd.navi.AppManager;
import com.xd.navi.NetWorkManager;
import com.xd.navi.OnNetStateChangeListener;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import butterknife.ButterKnife;

public  abstract   class BaseActivity extends AppCompatActivity implements OnNetStateChangeListener {


 //   protected NavController mNaviControll;

    protected abstract int initLayoutRes();

    protected abstract void loadData();

    protected abstract void upView();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppManager.getInstance().addActivity(this);
        setContentView(initLayoutRes());
        ButterKnife.bind(this);
        //初始化沉浸式
        initImmersionBar();
  //      mNaviControll = Navigation.findNavController(this, R.id.nav_host_fragment);
        //网络监听
        getLifecycle().addObserver(NetWorkManager.getInstance());
        NetWorkManager.getInstance().addListener(this);
        //初始化数据
        loadData();
        //绑定视图
        upView();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        NetWorkManager.getInstance().removeListener(this);
        AppManager.getInstance().removeActivity(this);
    }

    @Override
    public void onNetStateChange(boolean isConnect) {

    }


    /**
     * 初始化沉浸式
     */
    protected void initImmersionBar() {
        //设置共同沉浸式样式
        ImmersionBar.with(this).fitsSystemWindows(true).statusBarColor(R.color.main_color).init();
    }
}
